package edu.upenn.pcr.dao;

import edu.upenn.pcr.model.db.PennCourseReviewDBMgr;
import edu.upenn.pcr.model.db.dao.InstructorDAO;
import edu.upenn.pcr.model.db.entity.Instructor;
import edu.upenn.pcr.test.AndroidTestCaseBase;

public class InstructorDAOTest extends AndroidTestCaseBase {

	private PennCourseReviewDBMgr dbMgr;
	
	protected void setUp() throws Exception {
		super.setUp();
		dbMgr = PennCourseReviewDBMgr.getInstance(this.getTestContext());
	}
	
	public void testAddCount() {
		InstructorDAO dao = dbMgr.getInstructorDAO();
		dbMgr.beginTransaction();
		for (int i = 0; i < 10; i++) {
			Instructor instr = new Instructor();
			instr.setId(i+"");
			instr.setLastName("HAHA");
			instr.setFirstName("HEHE");
			instr.setViewed(0);
			dao.add(instr);
			int count = dao.count();
			assertEquals(i+1, count);
		}
		dbMgr.setTransactionSuccessful();
		dbMgr.endTransaction();
	}
	
	public void testFindById() {
		InstructorDAO dao = dbMgr.getInstructorDAO();
		Instructor instr = new Instructor();
		instr.setId("123");
		instr.setLastName("HAHA");
		instr.setFirstName("HEHE");
		instr.setViewed(0);
		dao.add(instr);
		Instructor find = dao.findById("123");
		assertNotNull(find);
	}
}
